﻿using System;
using System.Web;
using RazakiBLL;

namespace RazakiSite.Classes
{
    public class CacheProvider : ICacheProvider
    {
        public void SetData(string key, object value)
        {
            //در شرایطی مقدار
            //HttpContext.Current
            //برابر با
            //null
            //می شود
            //HttpContext.Current.Cache[key] = value;
            HttpRuntime.Cache[key] = value;
        }

        public T GetData<T>(string key)
        {
            //var value = HttpContext.Current.Cache[key];
            var value = HttpRuntime.Cache[key];
            var castedValue = Convert.ChangeType(value, typeof (T));

            return (T) castedValue;
        }
    }
}